package com.whxy02.tolearn.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.whxy02.tolearn.app.beans.Content;
import com.whxy02.tolearn.app.dao.ContentDao;
import com.whxy02.tolearn.app.service.ContentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ContentServiceImpl implements ContentService {

    private QueryWrapper<Content> wrapper=new QueryWrapper<>();
    @Resource
    ContentDao contentDao;

    @Override
    public List<Content> getAll() throws Exception {
        return contentDao.selectList(null);
    }

    @Override
    public Content getById(Integer id) throws Exception {
        return contentDao.selectById(id);
    }

    @Override
    public int save(Content content) throws Exception {
        return contentDao.insert(content);
    }

    @Override
    public int removeById(Integer id) throws Exception {
        return contentDao.deleteById(id);
    }

    @Override
    public int change(Content content) throws Exception {
        return contentDao.updateById(content);
    }

    @Override
    public Content getByQuestionId(Integer id) throws Exception {
        wrapper.clear();
        wrapper.eq("question_id",id);
        return contentDao.selectOne(wrapper);
    }

    @Override
    public boolean notHasContent(String content) throws Exception {
        wrapper.clear();
        wrapper.eq("content",content);
        return contentDao.selectOne(wrapper)==null;
    }
}
